#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#include <immintrin.h>
//#include <emmintrin.h>
#define ll long long
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define fi first
#define se second
#define pii pair<int,int>
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i,  b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=2e5+5,base=999983,Mod=998244353;
char buf[(1<<21)+5],*p1,*p2;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline void chmx(int &x,int y){(x<y)&&(x=y);}
inline void chmn(int &x,int y){(x>y)&&(x=y);}
inline void Add(int &x,int y){(x=x+y+Mod)%=Mod;}
inline ll read(){
	ll f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
void print(int n){
    if(n<0){
        putchar('-');
        n*=-1;
    }
    if(n>9) print(n/10);
    putchar(n%10+'0');
}
int n,Q;
vector<pii>q[N];
int fa[N][19],dep[N];
ll f[N];
int bg[N],ed[N],idx;
void dfs(int x,int faz){
	fa[x][0]=faz;dep[x]=dep[faz]+1;
	bg[x]=++idx;
	For(i,1,18)fa[x][i]=fa[fa[x][i-1]][i-1];
	for(auto y:q[x]){
		if(y.fi==faz)continue;
		f[y.fi]=f[x]+y.se;
		dfs(y.fi,x);
	}ed[x]=idx;
}
inline int LCA(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	Rof(i,18,0) if(dep[fa[x][i]]>=dep[y])x=fa[x][i];
	if(x==y)return x;
	Rof(i,18,0)if(fa[x][i]!=fa[y][i])x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}inline ll dis(int x,int y){
	return f[x]+f[y]-2ll*f[LCA(x,y)];
}int lg[N],st1[19][N],st2[19][N];
inline int qrymx(int l,int r){
	int k=lg[r-l+1];
	return max(st1[k][l],st1[k][r-(1<<k)+1]);
}
inline int qrymn(int l,int r){
	int k=lg[r-l+1];
	return min(st2[k][l],st2[k][r-(1<<k)+1]);
}

int rt[N],cnt;
struct SG_TREE{
	int l,r,x;
}tr[N*18];
void updata(int &x,int l,int r,int p){
	tr[++cnt]=tr[x];
	x=cnt;tr[x].x++;
	if(l==r)return;
	int mid=(l+r)>>1;
	if(p<=mid) updata(tr[x].l,l,mid,p);
	else updata(tr[x].r,mid+1,r,p);
}bool Flag=0;
pair<pii,pii>eQ[105];
inline bool query(int X,int Y,int LL,int RR){
	int L=1,R=0;
	eQ[++R]={{X,Y},{1,n}}; 
	int x,y,l,r;
	while(L<=R){ 
		x=(eQ[L]).fi.fi;
		y=(eQ[L]).fi.se;
		l=(eQ[L]).se.fi;
		r=(eQ[L]).se.se;L++;
		if(tr[x].x==tr[y].x)continue;
		if(LL<=l&&r<=RR){
			if(tr[x].x!=tr[y].x)return 1;
			continue;
		}int mid=(l+r)>>1;
		if(LL<=mid)eQ[++R]={{tr[x].l,tr[y].l},{l,mid}};
		if(RR>mid)eQ[++R]={{tr[x].r,tr[y].r},{mid+1,r}};
		
	}return 0;
}
signed main(){
	srand(time(0));
	freopen("memory.in","r",stdin);
	freopen("memory.out","w",stdout);
	// ios::sync_with_stdio(false);
	// cin.tie(0); cout.tie(0);
	lg[0]=-1;
	For(i,1,N-5) lg[i]=lg[i>>1]+1;
	n=read(),Q=read();
	For(i,1,n-1){ 
		int u=read(),v=read(),w=read();
		q[u].emplace_back(v,w);
		q[v].emplace_back(u,w);
	}
	dfs(rand()%n+1,0);
	For(i,1,n)st1[0][i]=bg[i];
	For(i,1,n)st2[0][i]=bg[i];
	For(j,1,18)For(i,1,n-(1<<j)+1){
		st1[j][i]=max(st1[j-1][i],st1[j-1][i+(1<<(j-1))]);
		st2[j][i]=min(st2[j-1][i],st2[j-1][i+(1<<(j-1))]);
	}ll lstans=0;
	For(i,1,n){
		rt[i]=rt[i-1];
		updata(rt[i],1,n,bg[i]);
	}
	while(Q--){
		ll p=read(),l=read(),r=read();
		p^=lstans;l^=lstans;r^=lstans;
		int x=LCA(p,l);
		int R=qrymx(l,r),L=qrymn(l,r);
		if(bg[l]<=L&&R<=ed[l]&&l!=x){
			printf("%lld\n",lstans=dis(l,p));
			continue;
		}
		int u=l;
		Rof(i,lg[dep[l]-dep[x]],0){
			if(dep[fa[u][i]]>dep[x]){
				if(bg[fa[u][i]]>L||ed[fa[u][i]]<R){
					u=fa[u][i];
				}
			}
		}
		if(dep[fa[u][0]]>dep[x]){
			printf("%lld\n",lstans=dis(fa[u][0],p));
			continue;
		}
		if(query(rt[l-1],rt[r],bg[p],ed[p])){
			printf("%lld\n",lstans=0);
			continue;
		}
		u=p;
		Rof(i,lg[dep[p]-dep[x]],0){
			if(dep[fa[u][i]]>dep[x]){
				if(!query(rt[l-1],rt[r],bg[fa[u][i]],ed[fa[u][i]]))u=fa[u][i];
			}
		}u=fa[u][0];
		printf("%lld\n",lstans=dis(u,p));
		
		
	}
#ifdef LOCAL
    Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

